package com.yc.fav.servlet;

import com.google.gson.Gson;
import com.yc.fav.entity.FavFavorite;
import com.yc.fav.entity.FavTag;
import com.yc.fav.mapper.FavTagMapper;
import com.yc.fav.util.MybatisHelper;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 1.继承
 * 2.重写
 * 3.配置
 */
@WebServlet("/ftags.do")
public class QueryNoTypeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try(SqlSession session = MybatisHelper.getSession()){
            FavTagMapper mapper = session.getMapper(FavTagMapper.class);
            List<FavFavorite> favFavorites = mapper.selectByFlags();
            resp.setContentType("application/json;charset=utf-8");
            String json = new Gson().toJson(favFavorites);
            resp.getWriter().print(json);
        }
    }
}
